/**
* @file EphFileReader.hpp
* Class to read and store the leapsec data.
*/

#ifndef GPSTK_EPH_FILE_READER_HPP
#define GPSTK_EPH_FILE_READER_HPP


//============================================================================
//
//  Shoujian Zhang, Wuhan University, 2019.5.4
//
//============================================================================


#include <iostream>
#include <string>
#include <set>
#include <map>
#include "CommonTime.hpp"

#include "SP3EphemerisStore.hpp"
#include "Rinex3EphemerisStore2.hpp"
#include "MGEXDCBReader.hpp"
#include "IFCBStore.hpp"
#include "MSCStore.hpp"
#include "PhaseBiasStore.hpp"

using namespace std;

namespace gpstk
{


      /** This class will read the data from the files givien 
       *  in the configuration file, mainly consists:
       *  (1) eopfile;
       *  (2) leap sec file;
       *  (3）jpl ephemeris file;
       *  (4) antex file from IGS;
       *  (5) blq file;
       *  (6) trop file, e.g. vinenna;
       */

   class EphFileReader
   {
   public:


         /// Default constructor
      EphFileReader()
          :
          pSP3Store(NULL),
          pNAVStore(NULL),
          pMGEXDCBStore(NULL),
          pIFCBStore(NULL),
          pMSCStore(NULL)
      {};


         /// Load the leap second data from input file
      void loadEPH()
         noexcept(false);

         /// Load the leap second data from input file
      void loadDCB()
         noexcept(false);

         /// Load the leap second data from input file
      int loadIFCB()
         noexcept(false);
      
         /// Load the leap second data from input file
      void loadMSC()
         noexcept(false);

      EphFileReader& setDataStores(
                            SP3EphemerisStore& sp3Store,
                            Rinex3EphemerisStore2& navStore,
                            MGEXDCBReader& dcbStore,
                            IFCBStore& ifcbStore,
                            MSCStore& mscStore)
      {
          pSP3Store = &sp3Store;
          pNAVStore = &navStore;
          pMGEXDCBStore = &dcbStore;
          pIFCBStore = &ifcbStore;
          pMSCStore = &mscStore;

          return (*this);
      };

      EphFileReader& setDataStores(
                            SP3EphemerisStore& sp3Store,
                            MGEXDCBReader& dcbStore,
                            IFCBStore& ifcbStore,
                            MSCStore& mscStore)
      {
          pSP3Store = &sp3Store;
          pMGEXDCBStore = &dcbStore;
          pIFCBStore = &ifcbStore;
          pMSCStore = &mscStore;

          return (*this);
      };

      EphFileReader& setDataStores(
                            SP3EphemerisStore& sp3Store,
                            MGEXDCBReader& dcbStore,
                            MSCStore& mscStore)
      {
          pSP3Store = &sp3Store;
          pMGEXDCBStore = &dcbStore;
          pMSCStore = &mscStore;

          return (*this);
      };

      EphFileReader& setDataFiles(string ephIndexFile, 
                                  string clkIndexFile, 
                                  string navIndexFile, 
                                  string dcbIndexFile, 
                                  string ifcbIndexFile,
                                  string mscIndexFile) 
      {
          ephIdxFile = ephIndexFile;
          clkIdxFile = clkIndexFile;
          navIdxFile = navIndexFile;
          dcbIdxFile = dcbIndexFile;
          ifcbIdxFile = ifcbIndexFile;
          mscIdxFile = mscIndexFile;
          return (*this);
      };

      EphFileReader& setDataFiles(string ephIndexFile, 
                                  string clkIndexFile, 
                                  string dcbIndexFile, 
                                  string ifcbIndexFile,
                                  string mscIndexFile) 
      {
          ephIdxFile = ephIndexFile;
          clkIdxFile = clkIndexFile;
          dcbIdxFile = dcbIndexFile;
          ifcbIdxFile = ifcbIndexFile;
          mscIdxFile = mscIndexFile;
          return (*this);
      };

      EphFileReader& setDataFiles(string ephIndexFile, 
                                  string clkIndexFile, 
                                  string dcbIndexFile, 
                                  string mscIndexFile) 
      {
          ephIdxFile = ephIndexFile;
          clkIdxFile = clkIndexFile;
          dcbIdxFile = dcbIndexFile;
          mscIdxFile = mscIndexFile;
          return (*this);
      };

      EphFileReader& setDCBStore(
                            MGEXDCBReader& dcbStore)
      {
          pMGEXDCBStore = &dcbStore;
          return (*this);
      };

      EphFileReader& setDCBFile( string dcbIndexFile)
      {
          dcbIdxFile = dcbIndexFile;
          return (*this);
      };

         /// clear the all the data
      void clear()
      {
          if(pSP3Store!=NULL) 
              pSP3Store->clear();

          if(pNAVStore!=NULL) 
              pNAVStore->clear();

          if(pMGEXDCBStore!=NULL) 
              pMGEXDCBStore->clear();

          if(pMSCStore!=NULL) 
              pMSCStore->clear();

          if(pIFCBStore!=NULL) 
              pIFCBStore->clear();

      }



         /// Default deconstructor
      virtual ~EphFileReader()
      {}


   private:

      string ephIdxFile, 
             clkIdxFile, 
             navIdxFile,
             dcbIdxFile, 
             ifcbIdxFile,
             eopIdxFile, 
             mscIdxFile,
             updMWIdxFile,
             updLCIdxFile;

      SP3EphemerisStore*     pSP3Store;
      Rinex3EphemerisStore2* pNAVStore;
      MGEXDCBReader*         pMGEXDCBStore;
      IFCBStore*             pIFCBStore;
      MSCStore*              pMSCStore;

   }; // End of class 'EphFileReader'

      // @}

}  // End of namespace gpstk


#endif   // GPSTK_EPH_FILE_READER_HPP
